package com.ztgf.shopping.api.client.epg;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgSectionCommodityRelationBO;
import com.ztgf.shopping.models.dto.epg.EpgSectionCommodityRelationDTO;
import com.ztgf.shopping.models.service.epg.IEpgSectionCommodityRelationService;
import com.ztgf.shopping.models.vo.epg.EpgSectionCommodityRelationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 频道栏目商品控制器
 *
 * @author YUE
 * @create 2020-05-18 11:36
 */

@RestController
@RequestMapping("/api/epgSectionCommodityRelation")
@Slf4j
@Api(value = "EpgSectionCommodityRelationApiController",tags = "频道栏目商品表Api接口")
public class EpgSectionCommodityRelationApiController {

    @DubboReference
    private IEpgSectionCommodityRelationService epgSectionCommodityRelationService;

    @ApiOperation(value = "频道栏目商品表根据频道id",notes = "频道栏目商品表根据频道id")
    @PostMapping("/getListBySectionId")
    public Result<List<EpgSectionCommodityRelationVO>> getListBySectionId(Long sectionId){
        EpgSectionCommodityRelationBO epgSectionCommodityRelationBO = new EpgSectionCommodityRelationBO();
        epgSectionCommodityRelationBO.setSectionId(sectionId);
        List<EpgSectionCommodityRelationVO> sectionCommodityRelationVOList = epgSectionCommodityRelationService.getListBySectionId(sectionId);
        return new Result<>(sectionCommodityRelationVOList);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgSectionCommodityRelationDTO> get(Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        EpgSectionCommodityRelationDTO epgSectionCommodityRelationDTO = epgSectionCommodityRelationService.selectById(id);
        return new Result<>(epgSectionCommodityRelationDTO);
    }

    @ApiOperation(value = "频道栏目商品表",notes = "频道栏目商品表")
    @PostMapping("/queryPageList")
    public Result<Page<EpgSectionCommodityRelationDTO>> queryPageList(EpgSectionCommodityRelationBO epgSectionCommodityRelationBO){
        Wrapper<EpgSectionCommodityRelationDTO> wrapper = new EntityWrapper<>();
        Page<EpgSectionCommodityRelationDTO> page = new Page<>(epgSectionCommodityRelationBO.getPageNo(), epgSectionCommodityRelationBO.getPageSize());
        page = epgSectionCommodityRelationService.selectPage(page, wrapper);
        return new Result<>(page);
    }
}
